<template>
  <div class="administratorLog">
    <el-card>
      <div class="box">
        <el-input v-model="input" placeholder="请输入管理员ID/账号"></el-input>
        <el-button @click="logsOpBtn" class="btn">查询搜索</el-button>
      </div>

      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="管理员ID"> </el-table-column>
        <el-table-column prop="createTime" label="时间"> </el-table-column>
        <el-table-column prop="account" label="账号"> </el-table-column>
        <!-- <el-table-column prop="IP" label="IP"> </el-table-column> -->
        <el-table-column prop="content" label="日志"> </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="page"
        :limit.sync="pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
import Pagination from "@/components/Pagination"; // 分页
import { logsOp } from "@/api/SystemManagement";

export default {
  components: { Pagination },
  inject: ["reload"],
  data() {
    return {
      input: "",
      tableData: [],
      total: 0,
      page: 1, //页码
      pageSize: 10, //每页条数
    };
  },
  methods: {
    logsOp() {
      logsOp({
        account: "",
        page: this.page,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = parseInt(res.data.count);
        }
      });
    },
    //搜索
    logsOpBtn() {
      if (this.page !== 1) {
        this.page = 1;
      }
      logsOp({
        id: this.input,
        page: this.page,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = parseInt(res.data.count);
        }
      });
    },
    //分页
    getList() {
      logsOp({
        id: this.input,
        page: this.page,
        pageSize: this.pageSize,
      }).then((res) => {
        if (res.code == 0) {
          this.tableData = res.data.list;
          this.total = parseInt(res.data.count);
        }
      });
    },
  },
  created() {
    this.logsOp();
  },
};
</script>

<style lang="less" scoped>
.administratorLog {
  height: 100%;
  margin: 20px;
  .box {
    margin-bottom: 20px;
    .el-input {
      width: 200px;
      margin-right: 20px;
    }
  }
}
</style>